<?php

namespace app\admin\controller\shop;

use app\admin\model\ShopSettle;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="shop_settle")
 */
class Settle extends AdminController
{

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new ShopSettle();
        
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParams();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
            $data = [
                'code' => 0,
                'msg' => '',
                'count' => $count,
                'data' => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }

    /**
     * @NodeAnotation(title="审批")
     */
    public function handle()
    {
        $row = $this->model->find(input('id'));
        ($row['settle_status'] != 0) && $this->error('请勿重新审核');
        $re = $row->save(['settle_status' => input('status')]);
        $re && $this->success('处理成功') || $this->error('操作失败');
    }

    
}